package com.ruoyi.projects2.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.projects2.domain.JwUndergraduateResearchProjects;
import com.ruoyi.projects2.service.IJwUndergraduateResearchProjectsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 科研项目管理Controller
 * 
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/projects2/projects2")
public class JwUndergraduateResearchProjectsController extends BaseController
{
    @Autowired
    private IJwUndergraduateResearchProjectsService jwUndergraduateResearchProjectsService;

    /**
     * 查询科研项目管理列表
     */
    @PreAuthorize("@ss.hasPermi('projects2:projects2:list')")
    @GetMapping("/list")
    public TableDataInfo list(JwUndergraduateResearchProjects jwUndergraduateResearchProjects)
    {
        startPage();
        List<JwUndergraduateResearchProjects> list = jwUndergraduateResearchProjectsService.selectJwUndergraduateResearchProjectsList(jwUndergraduateResearchProjects);
        return getDataTable(list);
    }

    /**
     * 导出科研项目管理列表
     */
    @PreAuthorize("@ss.hasPermi('projects2:projects2:export')")
    @Log(title = "科研项目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JwUndergraduateResearchProjects jwUndergraduateResearchProjects)
    {
        List<JwUndergraduateResearchProjects> list = jwUndergraduateResearchProjectsService.selectJwUndergraduateResearchProjectsList(jwUndergraduateResearchProjects);
        ExcelUtil<JwUndergraduateResearchProjects> util = new ExcelUtil<JwUndergraduateResearchProjects>(JwUndergraduateResearchProjects.class);
        util.exportExcel(response, list, "科研项目管理数据");
    }

    /**
     * 获取科研项目管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('projects2:projects2:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jwUndergraduateResearchProjectsService.selectJwUndergraduateResearchProjectsById(id));
    }

    /**
     * 新增科研项目管理
     */
    @PreAuthorize("@ss.hasPermi('projects2:projects2:add')")
    @Log(title = "科研项目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JwUndergraduateResearchProjects jwUndergraduateResearchProjects)
    {
        SysUser user= SecurityUtils.getLoginUser().getUser();
        jwUndergraduateResearchProjects.setDeptId(104L);
        jwUndergraduateResearchProjects.setUserId(user.getUserId());
        return toAjax(jwUndergraduateResearchProjectsService.insertJwUndergraduateResearchProjects(jwUndergraduateResearchProjects));
    }

    /**
     * 修改科研项目管理
     */
    @PreAuthorize("@ss.hasPermi('projects2:projects2:edit')")
    @Log(title = "科研项目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JwUndergraduateResearchProjects jwUndergraduateResearchProjects)
    {
        return toAjax(jwUndergraduateResearchProjectsService.updateJwUndergraduateResearchProjects(jwUndergraduateResearchProjects));
    }

    /**
     * 删除科研项目管理
     */
    @PreAuthorize("@ss.hasPermi('projects2:projects2:remove')")
    @Log(title = "科研项目管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jwUndergraduateResearchProjectsService.deleteJwUndergraduateResearchProjectsByIds(ids));
    }
}
